<layout-header></layout-header>

<nav class="container-xl mb-3">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a routerLink="/welcome">首页</a></li>
        <li class="breadcrumb-item active">计划任务</li>
    </ol>
</nav>

<div class="container-xl mb-3">
    <div class="text-end mb-3">
        <a class="btn btn-secondary me-2" href="https://github.com/opentdp/wrest-plugin/tree/master/cronjob" target="_blank">插件市场</a>
        <button class="btn btn-primary" [routerLink]="['/cronjob/create']">添加</button>
    </div>

    <table class="table table-hover align-middle">
        <thead class="table-light">
            <tr>
                <th scope="col">#</th>
                <th scope="col">名称</th>
                <th scope="col" class="d-none d-sm-table-cell">计划</th>
                <th scope="col" class="d-none d-lg-table-cell">类型</th>
                <th scope="col" class="d-none d-md-table-cell">上次执行</th>
                <th scope="col" class="d-none d-xl-table-cell">下次执行</th>
                <th scope="col">操作</th>
            </tr>
        </thead>
        <tbody>
            @for (item of cronjobs; track item.rd) {
            <tr>
                <th scope="row">{{item.rd}}</th>
                <td>{{item.name}}</td>
                <td class="d-none d-sm-table-cell">
                    {{item.second}} {{item.minute}} {{item.hour}} {{item.day_of_month}} {{item.month}} {{item.day_of_week}}
                </td>
                <td class="d-none d-lg-table-cell">
                    {{cronjobTypes[item.type] && cronjobTypes[item.type].name || '-'}}
                </td>
                <td class="d-none d-md-table-cell">
                    @if (status[item.rd] && status[item.rd].prev_time > 0) {
                    {{status[item.rd].prev_time * 1000 | date: 'yyyy-MM-dd HH:mm:ss'}}
                    } @else {
                    -
                    }
                </td>
                <td class="d-none d-xl-table-cell">
                    @if (status[item.rd] && status[item.rd].next_time > 0) {
                    {{status[item.rd].next_time * 1000 | date: 'yyyy-MM-dd HH:mm:ss'}}
                    } @else {
                    -
                    }
                </td>
                <td class="text-nowrap">
                    <button class="btn btn-sm btn-success me-2" (click)="executeCronjob(item)" [disabled]="execStatus[item.rd]">触发</button>
                    <button class="btn btn-sm btn-primary me-2" routerLink="/cronjob/update/{{item.rd}}">编辑</button>
                    <button class="btn btn-sm btn-danger me-2" (click)="deleteCronjob(item)">删除</button>
                </td>
            </tr>
            }
        </tbody>
    </table>
</div>